package com.cn.wanxi.servlet;

import com.cn.wanxi.dao.CompanyDao;
import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.model.NavModel;
import com.cn.wanxi.model.NewsModel;
import com.cn.wanxi.service.CompanyService;
import com.cn.wanxi.service.NavService;
import com.cn.wanxi.service.NewsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/home")
public class HomeServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


        /**
         * 作用域  需要将值存入到容器里面，对页面进行传值
         * page  当前页面,不能跨页面
         * request 请求页面，只能在请求页面访问
         * session  整个会话期，不能跨浏览器
         * application  整个项目,可以跨浏览器
         */
//        req.setAttribute("logo","../img/logo_g0yv.jpg");
//        req.setAttribute("phone","028-9999999999");
//        req.setAttribute("net","028-9999999999");
//        req.setAttribute("email","028-9999999999");

//        CompanyModel companyModel = new CompanyModel();

//        CompanyService companyService = new CompanyService();
//        CompanyModel companyModel = companyService.getCompanyModel();
//        req.setAttribute("companyModel", companyModel);


//  对于导航 是由无数个相同的对象组成   数组
//        数组的定义？为什么要用数组？如果有很多的元素一样，则可以将他们装在一起，可以用数组（容器）,list 集合
//     静态定义，动态定义
//        String name = null;
//        NavService navService = new NavService();
//        NavModel[] navModels = navService.getNavModels();
//
//        req.setAttribute("navModels", navModels);//key-value的形式


        CommonServlet.setCompanyAndNavData(req);

//        新闻数据
        NewsService newsService=new NewsService();
        NewsModel[] newsModels=newsService.getNewsModelsForHomePage();

        req.setAttribute("newsModels",newsModels);

        req.getRequestDispatcher("/jsp/home.jsp").forward(req, resp);
    }
}
